package com.lcxw.hxzbadmin.controller.jubaocontroller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lcxw.hxzbadmin.entity.requestbean.DealJubaoReq;
import com.lcxw.hxzbadmin.entity.requestbean.GetJubaoListReq;
import com.lcxw.hxzbadmin.entity.requestbean.RequestBodyBasic;
import com.lcxw.hxzbapi.entity.pojo.Jubao;
import com.lcxw.hxzbapi.entity.response.Response;
import com.lcxw.hxzbapi.entity.response.ResponseData;
import com.lcxw.hxzbapi.service.JubaoService;
import java.util.List;
import javax.annotation.Resource;

import com.lcxw.hxzbapi.tencentim.common.ImCommand;
import com.lcxw.hxzbapi.tencentim.common.TencentImRealization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/jubao")
public class JubaoController {

    @Resource
    JubaoService jubaoService;


    @Autowired
    private TencentImRealization tencentImRealization;

    @PostMapping("/getList")
    public Response getJubaoList(@RequestBody GetJubaoListReq requestBody) {

        int pageNum = requestBody.getPageNum();
        int pageSize = requestBody.getPageSize();
        String status = requestBody.getStatus();
        IPage<Jubao> list = jubaoService.getList(status, pageNum, pageSize);
        long total = list.getTotal();
        List<Jubao> records = list.getRecords();
        ResponseData responseData = new ResponseData();
        responseData.setTotal(total);
        responseData.setList(records);
        return Response.ok(responseData);
    }

    @PostMapping("/deal")
    public Response dealJubao(@RequestBody DealJubaoReq dealJubaoReq) {
        int id = dealJubaoReq.getId();
        Jubao jubao = jubaoService.selectById(id);
        jubao.setStatus("1");
        jubaoService.updateById(jubao);
        //根据不同的类型通知用户什么内容被投诉。
        String source=jubao.getSource();
        String str="";
        switch (source){
            case "video":
                str="视频";
                break;
            case "'room'":
                str="聊天室";
                break;
            case "'dynamic'":
                str="动态";
                break;
            case "'user'":
                str="个人信息";
                break;
        }
        Response msg = new Response();
        msg.setCode(ImCommand.COMPLAINT_NOTICE);
        msg.setDesc("经举报核实,你的"+str+"中存在违规信息,请注意社交礼仪。");
        msg.setData(jubao.getId());
        tencentImRealization.sendmsg(tencentImRealization.generateUserBody(JSON.toJSONString(msg),jubao.getUserId()));
        return Response.ok();
    }
}
